﻿#ifndef JZNET_MANAGER_H_
#define JZNET_MANAGER_H_

#include <QObject>
#include <QMap>
#include <QByteArray>
#include <QVector>
#include <QTcpSocket>
#include <QSharedPointer>
#include <QJsonObject>

class JZRpcDataManager
{
public:	
    JZRpcDataManager();
	~JZRpcDataManager();

	void newSession(int sessionId, QTcpSocket*);
	void endSession(int sessionId);
	
    bool sendPack(int sessionId, const QJsonObject &pack);
	void recvPack(int sessionId);		
	void recvData(int sessionId, QByteArray data);	
	
	void parsePack(int sessionId);
	QJsonObject takePack(int sessionId);
	int packCount(int sessionId);

    QTcpSocket *socket(int sessionId);

private:		
    QByteArray packData(const QJsonObject &pack);

	struct SessionInfo
	{
		QTcpSocket *socket;
		QVector<QJsonObject> packList;
		QByteArray buffer;		
	};			
	QMap<int, SessionInfo> m_sessionInfo;	
};

#endif
